<!DOCTYPE html>
<html>

<head>
    <title>腰臀比测量</title>
	<titleType style="display: none">healthTest</titleType>
	<%- include('../../_global/baseLibs') %>
	<%- include('measurement.ejs') %>

    <style type="text/css">
    	.background{
			height: 100%;
			width: 100%;
			background: #fff;
		}
    </style>
</head>

<body>
<!-- header start -->
<header id="header" class="header-box grey fixed"  >
	<div class="header-content">
		<div class="left-tool">
			<a class="back" href="javascript:void(0)"><i class="iconfont icon-back"></i></a>
		</div>
		<div class="title">WHR测量</div>
		<div class="right-tool">
			<a class="tool-a" >提交</a>
		</div>
	</div>
</header>
<!-- header end -->

	<div class="mui-content">
		<div class="background">
			<!-- 头部导航栏 -->
			<div class="topBar">
				<div class="text">
					<a id="id_a" onclick="changeTime('testTime')">
						<img alt="" src="/static/images/back.png">
						<span class="title" >测量时间</span>
						<span id="testTime" class="time" ></span>
					</a>
				</div>
				<div class="line"></div>
			</div>

			<!-- 标尺块 -->
			<div id="yw-box" class='box'>
				<span class="title" >腰围</span>
				<div class='valueplus'>                                                                                                                           
					<div class='minus' ><a><img id="minus_img" src="/static/images/measurement/selfTest/minus.png"></a></div>
					<div class='value' ><span id='waist' >0</span><span id='waist_unit'>cm</span></div>
					<div class='plus' ><a><img id="add_img" src="/static/images/measurement/selfTest/add.png"></a></div>
				</div>
				<div id='waistRuler'></div>
			</div>
			<!-- 标尺块 -->
			<div id="tw-box" class='box'>
				<span class="title" >臀围</span>
				<div class='valueplus'>                                                                                                                           
					<div class='minus' ><a><img id="hipminus_img" src="/static/images/measurement/selfTest/minus.png"></a></div>
					<div class='value' ><span id='hip' >0</span><span id='hip_unit'>cm</span></div>
					<div class='plus' ><a><img id="hipadd_img" src="/static/images/measurement/selfTest/add.png"></a></div>
				</div>
				<div id='hipRulerWrapper'></div>
			</div>
			
			<div class="footer">
				<span>BMI:</span>
				<span id='footer_value'>20.8（正常）</span>
			</div>
			
		</div>
	</div>
<button id="titleBtn"   style="width: 100%;height:40px;color: #3082FF;position: fixed;bottom: 0px;;display: none;">提交</button>

	<script type="text/javascript">



        var page_whrMobile = (function($, page_whrMobile) {

            /*类型*/
            var cllx = '05';
            mui.init({
                swipeBack:false //启用右滑关闭功能
            });
            //回调函数 改变数值和颜色
            function rulerSetValue(val){
                $("#waist").html(parseInt(val));
                if(val >= 50 && val <= 150 ){
                    $('#waist').css("color","#40BDFF");
                    $('#waist_unit').css("color","#40BDFF");
                }else{
                    $('#waist').css("color","#FDB178");
                    $('#waist_unit').css("color","#FDB178");
                }
                page_whrMobile.setWHR();
            }

            //回调函数 改变数值和颜色
            function rulerSetHeartRate(val){
                $("#hip").html(parseInt(val));
                if(val >= 50 && val <= 150 ){
                    $('#hip').css("color","#40BDFF");
                    $('#hip_unit').css("color","#40BDFF");
                }else{
                    $('#hip').css("color","#FDB178");
                    $('#hip_unit').css("color","#FDB178");
                }
                page_whrMobile.setWHR();
            }

            /*
			* 提交BWHR测量数据
			*/
            function submitWHR(){
                var data = page_whrMobile.getData();
                $.QuickRemote.AjaxJson({
                    funcName: uri_service_tzcl_save
                    , params: data
                    , callback: function (result) {
                        $.QuickAlert.alertNormal("保存成功", {
                            callback: function(){
                                var url =$.getUrl.pageUrl("measurement","selfTest_mobile");
                                var data = {refreshUrl:url,pageUrl:url};
                                $.QuickUrlUtils.refreshJSBridge(data);
                                $.pageSwitch.goToUrl("measurement","records_mobile","cllx=" + cllx);
                            }
                        })
                    }
                });
            }

            function getData() {
                /*测量时间*/
                var clsj = $("#testTime").text();
                /*腰围*/
                var yw = $("#waist").text();
                /*臀围*/
                var tw = $("#hip").text();
                return {
                    cllx: cllx
                    ,clsj: clsj
                    , yw: yw
                    , tw: tw
                };
            }

            function setWHR(){
                var waist = parseFloat($("#waist").text());
                var hip = parseFloat($("#hip").text());
                var whr = waist / hip;
                if(whr > 0.9){
                    $('#footer_value').html(whr.toFixed(2)+'（中心性肥胖）');
                    $('#footer_value').css("color","#FDB178");
                }else{
                    $('#footer_value').html(whr.toFixed(2)+'（正常）');
                    $('#footer_value').css("color","#8f8f94");
                }
            }

            var cfg_def = {
                rulerSetValue: rulerSetValue,
                rulerSetHeartRate: rulerSetHeartRate,
                submitWHR: submitWHR,
                getData: getData,
                setWHR: setWHR,
            }


            //初始化尺子  腰围
            var waistRuler =new MeasureRuler({
                wrapperId:"waistRuler",
                max:150,
                minUnit:1,// 每个刻度代表的值
                unitSet:10, // 每组刻度个数
                startValue : 50,
                mult:1, //10px
                value:75,
                greenLeft : 50,
                greenRight : 150,
                callback:page_whrMobile.rulerSetValue
            });

            var hipWrapper=new MeasureRuler({
                wrapperId:"hipRulerWrapper",
                max:150,
                minUnit:1,// 每个刻度代表的值
                unitSet:10, // 每组刻度个数
                startValue : 50,
                mult:1, //10px
                value:80,
                greenLeft : 50,
                greenRight : 150,
                callback:page_whrMobile.rulerSetHeartRate
            });

            page_whrMobile.init = function(cfg){
                $.extend(page_whrMobile, cfg_def, cfg);


                initRule("yw-box", waistRuler, 1);
                initRule("tw-box", hipWrapper, 1);
                var date = new Date();
                $('#testTime').text(date.Format('yyyy-MM-dd HH:mm:ss'));
                $(".tool-a").on ("click", page_whrMobile.submitWHR);
//                if( u.indexOf('micromessenger') != -1){
//                    $("#titleBtn").show();
//                }
                $("#titleBtn").on ("click", page_whrMobile.submitWHR);

            }

            return page_whrMobile;
        })(jQuery, {});
		
	</script>
</body>

</html>